<?php namespace Home\Controller;

//公司控制器
class CompanyController extends CheckController{
	private $model;//存放模型对象
	private $jobModel;//存放模型对象
	//自动执行函数
	public function __doit(){
		//实例化公司表
		$this->model=new \Common\Model\Company;
		//实例化职位表
		$this->jobModel=new \Common\Model\Job;
	}

	//公司主页
	public function index(){
		if (IS_POST) {
			if (!$this->model->edit()) View::error($this->model->getError());
			View::success('修改成功');
		}
		//获得并分配公司数据
		$data=$this->model
					->join('company_data','gsid','=','lg_company_gsid')
					->where("lg_user_uid={$_SESSION['homeInfo']['uid']}")
					->find();
		//获得上线职位的信息
		$jobData=$this->jobModel->where("lg_company_gsid={$data['gsid']}")->get();
		$num=count($jobData);
		View::with('num',$num);
		View::with('data',$data)->make();
	}

	//招聘职位列表
	public function jobMsg(){
		//获得并分配公司数据
		$data=$this->model
					->join('company_data','gsid','=','lg_company_gsid')
					->where("lg_user_uid={$_SESSION['homeInfo']['uid']}")
					->find();
		//获得上线职位的信息
		$jobData=$this->jobModel->where("lg_company_gsid={$data['gsid']}")->get();
		$num=count($jobData);
		View::with('jobData',$jobData);
		View::with('num',$num);
		View::with('data',$data)->make();
	}

	//uploadify异步上传
	public function upload(){
	    $file = Upload::path('Upload/Content/' . date('y/m'))->make();
	    if (empty($file)) {
	        // 相当于：echo json_encode(Upload::getError());exit;
	        $this->ajax(Upload::getError());
	    } else {
	        /** $file内部就是以下这个数组
	            $file = array(
	                0 => array(
		                'path' => 'Upload/Content/15/8/123981239172.jpg'    ,
		                'url' => 'http://localhost/cms_edu/Upload/Content/15/8/123981239172.jpg',
		                'image' => 1
	            ),
	        );**/
	        //上传成功，把上传好的信息返给js 也就是uploadify
	        $data = $file[0];
	        // 相当于：echo json_encode($data);exit;
	        $this->ajax($data);
	    }
	}

	//uploadify异步删除
	public function delUpload(){
		$path=Q('post.oldImg');
		if (unlink($path)) {
			echo 1;
		}else{
			echo 0;
		}
	}





}